<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 
 <%
	String basePath = request.getScheme()+"://"+request.getServerName()
		+ ":"+ request.getServerPort() + request.getContextPath() + "/";
%>
 
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath %>">
<meta charset="UTF-8">
<title>员工列表</title>
</head>
<body>
<a href="user/logout.do">退出登录</a>
<table border="1px" width="100%">
	<caption>员工列表</caption>
	<thead>
		<tr>
			<th>ID</th>
			<th>照片</th>
			<th>姓名</th>
			<th>电话</th>
			<th>部门</th>
			<th>生日</th>
			<th>操作</th>
		</tr>
	</thead>
	
	<tbody>
	</tbody>
	
</table>


<script type="text/javascript" src="js/jquery-2.1.4.js"></script>
<script type="text/javascript">

$.ajax({
	url:'emp/getAll.json',
	data:{},
	type:"post",
	dataType:"json",
	success:function(data){
		if(data.error != null){
			alert(data.error);
			return ;
		}
		var html ="";
		$.each(data,function(index,item){
			html += "<tr>"+
			"<td>"+item.eid+"</td>"+
			"<td>"+((item.ephoto!=null)?"<img width='50px' src='upload/"+item.ephoto+"'>":"")+"</td>"+
			"<td>"+item.ename+"</td>"+
			"<td>"+item.ephone+"</td>"+
			"<td>"+item.dname+"</td>"+
			"<td>"+dateFormat(item.ebirthday)+"</td>"+
			"<td><a href='emp/modify.do?eid="+item.eid+"'>修改</a>"+
				"<a href='emp/remove.do?eid="+item.eid+"'>删除</a></td>"+
			"</tr>"
		});
		$("tbody").html(html);
	},
	error:function(){
		console.log("请求失败")
	}
});

/* 通过JS对日期时间进行格式化操作 */
function dateFormat(date){
	var d = new Date(date);
	return d.getFullYear()+"年"+(d.getMonth()+1)+"月"+d.getDate()+"日";
}


</script>
</body>
</html>